home *** CD-ROM | disk | FTP | other *** search
/ GFX Sensations 1 / Graphic Sensations - Volume 1.iso / tools / amiga / 3d_tools / irit40s.lha / Irit / cagd_lib / cagdruld.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-30  |  3.8 KB  |  114 lines

  1. /******************************************************************************
  2. * CagdRuld.c - Ruled srf operator out of given two profiles.              *
  3. *******************************************************************************
  4. * Written by Gershon Elber, May. 91.                          *
  5. ******************************************************************************/
  6.  
  7. #include "cagd_loc.h"
  8.  
  9. /******************************************************************************
  10. * Constructs a ruled surface between the two provided curves. The two curves  *
  11. * must have the same number of points, same curve type and same point type.   *
  12. * OtherOrder and OtherLen (equal for Bezier) specifies the desired order and  *
  13. * refineness level (if Bspline) of the other ruled direction.              *
  14. ******************************************************************************/
  15. CagdSrfStruct *CagdRuledSrf(CagdCrvStruct *Crv1, CagdCrvStruct *Crv2,
  16.                 int OtherOrder, int OtherLen)
  17. {
  18.     CagdSrfStruct *Srf;
  19.     int i, j, k, MaxCoord, Len;
  20.     CagdPointType PType;
  21.     CagdBType IsNotRational;
  22.     CagdRType **SrfPoints, *Crv1SrcPt, *Crv2SrcPt, *SrfDestPt, t, t1,
  23.                          **Crv1Points, **Crv2Points;
  24.  
  25.     Crv1 = CagdCrvCopy(Crv1);
  26.     Crv2 = CagdCrvCopy(Crv2);
  27.  
  28.     CagdMakeCrvsCompatible(&Crv1, &Crv2, TRUE, TRUE);
  29.  
  30.     MaxCoord = CAGD_NUM_OF_PT_COORD(Crv1 -> PType),
  31.     Len = Crv1 -> Length;
  32.     PType = Crv1 -> PType;
  33.     IsNotRational = !CAGD_IS_RATIONAL_CRV(Crv1);
  34.     Crv1Points = Crv1 -> Points;
  35.     Crv2Points = Crv2 -> Points;
  36.  
  37.     switch (Crv1 -> GType) {
  38.     case CAGD_CBEZIER_TYPE:
  39.         Srf = BzrSrfNew(Len, OtherLen, PType);
  40.         break;
  41.     case CAGD_CBSPLINE_TYPE:
  42.         Srf = BspSrfNew(Len, OtherLen, Crv1 -> Order, OtherOrder, PType);
  43.         CAGD_GEN_COPY(Srf -> UKnotVector, Crv1 -> KnotVector,
  44.               sizeof(CagdRType) * (Len + Crv1 -> Order));
  45.         BspKnotUniformOpen(OtherLen, OtherOrder, Srf -> VKnotVector);
  46.         break;
  47.     case CAGD_CPOWER_TYPE:
  48.         FATAL_ERROR(CAGD_ERR_POWER_NO_SUPPORT);
  49.         return NULL;
  50.     default:
  51.         FATAL_ERROR(CAGD_ERR_UNDEF_CRV);
  52.         return NULL;
  53.     }
  54.  
  55.     /* Copy the control mesh - first row is exactly the same as the first    */
  56.     /* curve while last row is the same as second curve.             */
  57.     /* The middle rows are convex blend of the first/last rows.             */
  58.     SrfPoints = Srf -> Points;
  59.  
  60.     for (i = IsNotRational; i <= MaxCoord; i++)               /* First row. */
  61.     CAGD_GEN_COPY(SrfPoints[i], Crv1Points[i],
  62.               sizeof(CagdRType) * Len);
  63.  
  64.     /* Make a copy of the last row. */
  65.     for (i = IsNotRational; i <= MaxCoord; i++)                /* Last row. */
  66.     CAGD_GEN_COPY(&SrfPoints[i][Len * (OtherLen - 1)], Crv2Points[i],
  67.               sizeof(CagdRType) * Len);
  68.  
  69.     /* And compute the internal rows, if any: */
  70.     for (j = 1; j < OtherLen - 1; j++) {
  71.     t = ((CagdRType) j) / (OtherLen - 1);
  72.     t1 = 1.0 - t;
  73.     for (i = IsNotRational; i <= MaxCoord; i++) {
  74.         SrfDestPt = &SrfPoints[i][Len * j];
  75.         Crv1SrcPt = Crv1Points[i];
  76.         Crv2SrcPt = Crv2Points[i];
  77.         for (k = 0; k < Len; k++)
  78.         SrfDestPt[k] = t1 * Crv1SrcPt[k] + t * Crv2SrcPt[k];
  79.     }
  80.     }        
  81.  
  82.     CagdCrvFree(Crv1);
  83.     CagdCrvFree(Crv2);
  84.  
  85.     return Srf;
  86. }
  87.  
  88. /******************************************************************************
  89. * Promote a curve to a surface by creating a ruled surface between the curve  *
  90. * and itself. Dir controls if the curve should be U or V surface direction.   *
  91. ******************************************************************************/
  92. CagdSrfStruct *CagdPromoteCrvToSrf(CagdCrvStruct *Crv, CagdSrfDirType Dir)
  93. {
  94.     CagdSrfStruct *TSrf,
  95.     *Srf = CagdRuledSrf(Crv, Crv, 2, 2);
  96.  
  97.     switch (Dir) {
  98.     case CAGD_CONST_U_DIR:
  99.         break;
  100.     case CAGD_CONST_V_DIR:
  101.         TSrf = CagdSrfReverse2(Srf);
  102.         CagdSrfFree(Srf);
  103.         Srf = TSrf;
  104.         break;
  105.     default:
  106.         FATAL_ERROR(CAGD_ERR_DIR_NOT_CONST_UV);
  107.         break;
  108.     
  109.     }
  110.     return Srf;
  111. }
  112.  
  113.  
  114.